﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Iguana.Core.HypterText.DocumentStructuralElements
{
    public class Head : IElement
    {
        private ElementType m_EType;
        private AttributeCollection m_AttributeCollection;
        private bool m_SelfClosing;
        private string m_Name;
        private string m_TagStart;
        private DocumentTypeCollection m_DocTypeCollection;
        private ElementCollection m_AllowedNestedElements;

        public Head()
        {
            m_EType = ElementType.DocumentStructure;
            m_AttributeCollection = new AttributeCollection();
            m_SelfClosing = false;
            m_Name = "Head";
            m_TagStart = "head";
            m_DocTypeCollection = UtilDocTypes.GetAllDocumentTypes();
            m_AllowedNestedElements = new ElementCollection();

            m_AllowedNestedElements.Add(new StandardElements.Title());


        }

        public ElementType Type
        {
            get
            {
                return m_EType;
            }
            set
            {
                throw new System.Data.ReadOnlyException(String.Format(SR.SR_EXC_READONLY, "Element Type"));
            }
        }

        public AttributeCollection Attributes
        {
            get
            {
                return m_AttributeCollection;
            }
            set
            {
                m_AttributeCollection = value;
            }
        }

        public bool SelfClosing
        {
            get
            {
                return m_SelfClosing;
            }
            set
            {
                throw new System.Data.ReadOnlyException(String.Format(SR.SR_EXC_READONLY, "Self Closing"));
            }
        }

        public string Name
        {
            get
            {
                return m_Name;
            }
            set
            {
                throw new System.Data.ReadOnlyException(String.Format(SR.SR_EXC_READONLY, "Name"));
            }
        }

        public string TagStart
        {
            get
            {
                return m_TagStart;
            }
            set
            {
                throw new System.Data.ReadOnlyException(String.Format(SR.SR_EXC_READONLY, "Tag Start"));
            }
        }

        public string TagEnd
        {
            get
            {
                return UtilElementWriter.WriteClosing(SelfClosing, TagStart);
            }
        }

        public DocumentTypeCollection SupportedDocTypes
        {
            get
            {
                return m_DocTypeCollection;
            }
            set
            {
                throw new System.Data.ReadOnlyException(String.Format(SR.SR_EXC_READONLY, "Supported Document Types"));
            }
        }

        public override string ToString()
        {
            return UtilElementWriter.WriteStartWithAttributes(TagStart, Attributes, true);
        }


        public ElementCollection AllowedNestedElements
        {
            get
            {
                return m_AllowedNestedElements;
            }
            set
            {
                m_AllowedNestedElements = value;
            }
        }
    }
}
